package name.luoyong.shiro.shiroIniCustom.filter.print;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.Authenticator;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.Authorizer;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.mgt.RememberMeManager;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.SessionManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.AccessControlFilter;
import org.apache.shiro.web.mgt.CookieRememberMeManager;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;

public class PrintSubjectFilter extends AccessControlFilter {

	@Override
	protected boolean isAccessAllowed(ServletRequest request,
			ServletResponse response, Object mappedValue) throws Exception {
		Subject subject = SecurityUtils.getSubject();
		
		DefaultSecurityManager securityManager = (DefaultSecurityManager) SecurityUtils
				.getSecurityManager();
		DefaultWebSecurityManager securityManager2 = (DefaultWebSecurityManager) securityManager;
		
		Authenticator authenticator = securityManager.getAuthenticator();
		Authorizer authorizer = securityManager.getAuthorizer();
		CacheManager cacheManager = securityManager.getCacheManager();
		SessionManager sessionManager = securityManager.getSessionManager();
		RememberMeManager rememberMeManager = securityManager.getRememberMeManager();
		CookieRememberMeManager cookieRememberMeManager = (CookieRememberMeManager) rememberMeManager;
		cookieRememberMeManager.getCookie().getMaxAge();
		Session session = subject.getSession();
		System.out.println("--------- printSubjectObject --------");
		System.out.println("securityManager : "+securityManager + "*****");
		System.out.println("subject : "+subject);
		System.out.println("authenticator : "+authenticator);
		System.out.println("authorizer : "+authorizer);
		System.out.println("sessionManager : "+sessionManager);
		System.out.println("subjectSessionId : "+session.getId());
		System.out.println("cacheManager : "+cacheManager);
		System.out.println("rememberMeManager : "+rememberMeManager);
		System.out.println("cookieRememberMeManager : "+cookieRememberMeManager);
		System.out.println("cookie maxAge : "+cookieRememberMeManager.getCookie().getMaxAge());
		System.out.println("******** end of printSubjectObject ********");
		System.out.println();
		
		return true;
	}

	@Override
	protected boolean onAccessDenied(ServletRequest request,
			ServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

}
